// src/api/course/index.ts
import {adminRequest, userRequest} from "@/utils/request.ts";
import type {AddAndEditCourse, AddOrEditOrDelResp, GetCourseResp, PageCourse, PageResp} from "@/type/course.ts";

enum API {
    GET_PAGE_COURSES_URL = '/admin/course/page',   // get
    GET_A_SINGLE_COURSE = '/admin/course/',   // /course/:id get
    CREATE_A_NEW_COURSE = '/admin/course',    // post
    UPDATE_COURSE_INFORMATION = '/admin/course', // /course/:id put
    DELETE_COURSE = '/admin/course/' // /course/:id delete
}

// 分页获取课程
export const getPageCourses = (pageData: PageCourse) => adminRequest.get<any, PageResp>(API.GET_PAGE_COURSES_URL, {params: pageData})

// 获取单个课程
export const getCourseById = (courseId: number) => adminRequest.get<any, GetCourseResp>(`${API.GET_A_SINGLE_COURSE}${courseId}`)

// 创建新课程
export const createCourse = (course: Omit<AddAndEditCourse, 'courseId'>) => adminRequest.post<any, AddOrEditOrDelResp>(API.CREATE_A_NEW_COURSE, course)

// 更新课程信息
export const updateCourse = (course: AddAndEditCourse) => adminRequest.put<any, AddOrEditOrDelResp>(API.UPDATE_COURSE_INFORMATION, course)

// 删除课程
export const deleteCourse = (courseId: number) => adminRequest.delete<any, AddOrEditOrDelResp>(`${API.DELETE_COURSE}${courseId}`)


// 客户端
enum MEMBER_API {
    GET_PAGE_COURSES_URL = '/member/course/page'
}

export const memberGetPageCourses = (pageData: PageCourse) => userRequest.get<any, PageResp>(MEMBER_API.GET_PAGE_COURSES_URL, {params: pageData})